package com.victor.service.impl;

import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.victor.dao.SeriesDao;
import com.victor.dao.SeriesandpicbookDao;
import com.victor.entity.Series;
import com.victor.service.SeriesService;

@Service
@Transactional
public class SeriesServiceImpl implements SeriesService {

	@Autowired
	private SeriesDao dao;
	@Autowired
	private SeriesandpicbookDao sapDao;

	@Override
	public boolean batchDelete(int[] ids) {
		return dao.batchDelete(ids) > 0 ? true : false;
	}

	@Override
	public boolean insertSeries(Series record) {
		return dao.insertSeries(record) > 0 ? true : false;
	}

	@Override
	public Series findById(Integer sId) {
		return dao.findById(sId);
	}

	@Override
	public boolean update(Series record) {
		return dao.update(record) > 0 ? true : false;
	}

	@Override
	public boolean saveSeries(Series series, int[] pictureIds) {
		int insertSeries = dao.insertSeries(series);
		if (insertSeries <= 0) {
			return false;
		}
		if (pictureIds != null && pictureIds.length > 0) {
			int batchInsert = sapDao.batchInsert(series.getSId(), pictureIds);
			if (batchInsert <= 0) {
				return false;
			}
		}
		return true;
	}

	@Override
	public List<Series> getSeries(String sName,int[] ageIds, int[] categoryIds, Integer copyrightid,String flag) {
		return dao.getSeries(sName,ageIds, categoryIds, copyrightid,flag);
	}

	@Override
	public List<Series> getAudioSeries(String sName, int[] ageIds, int[] categoryIds, Integer copyrightid,String flag) {
		return dao.getAudioSeries(sName, ageIds, categoryIds, copyrightid,flag);
	}

	@Override
	public List<Map<String, String>> getSearch(String name,  int[] ageIds, int[] categoryIds,String pictype,String userid,String flag) {
		return dao.getSearch(name,ageIds,categoryIds,pictype,userid,flag);
	}

	@Override
	public Map<String,String> getDetails(Integer sid) {
		return dao.getDetails(sid);
	}

	@Override
	public List<Map<String, String>> getPicByCategory(String pictype, String userid) {
		return dao.getPicByCategory(pictype,userid);
	}

	@Override
	public boolean updateService(Series series, int[] pictureIds) {
		int insertSeries = dao.update(series);
		if (insertSeries <= 0) {
			return false;
		}
		if (pictureIds != null && pictureIds.length > 0) {
			int batchInsert = sapDao.batchInsert(series.getSId(), pictureIds);
			if (batchInsert <= 0) {
				return false;
			}
		}
		return true;
	}

}
